Skip to content

fix: start an empty deserialized sketch from a valid HIP state - #579

Merged
proost merged 1 commit into
apache:masterfrom
proost:fix-cpc-empty-deserialize-kxp
Nov 15, 2026
Merged

proost merged 1 commit into
apache:masterfrom
proost:fix-cpc-empty-deserialize-kxp

Conversation

@proost

@proost proost commented Nov 14, 2026

Copy link
Copy Markdown
Member

Empty sketch has no HIP value.

So during deserialization, we should start kxp as 2^lgk.

If not, after deserialization and then update some value then estimation become inf.

@proost
proost requested a review from leerho November 14, 2026 13:39
@proost proost self-assigned this Nov 14, 2026

@leerho leerho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The fix is correct and matches Java.

  • The bug: a never-merged empty CPC sketch is serialized with its HIP flag set but without the HIP fields. Those are only written alongside a table or window. So the reader left kxp at 0, and the first update after deserializing computed k / kxp, which made the estimate infinite.
  • The fix: start kxp at 1 << lg_k, the same value a new sketch’s constructor uses, and the same as Java’s CompressedState. Images that carry the HIP fields still overwrite it.
  • Testing: I merged it with current master. All 52 CPC test cases pass under ASan and UBSan, and so do the Java-file tests, including its new cpc_n0_java.sk case. Its new test fails on master’s code with exactly the bug: an estimate of inf instead of 997.6.

@proost
proost merged commit 6f4d571 into apache:master Nov 15, 2026
21 checks passed
@proost
proost deleted the fix-cpc-empty-deserialize-kxp branch November 15, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants